package com.test.common.unmutable;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class MonitorVihicleTracher {
    private final ConcurrentHashMap<String, UnMutablePoint> locations;
    private final Map<String, UnMutablePoint> unmutableMap;

    public MonitorVihicleTracher(Map<String, UnMutablePoint> inputMap) {
        locations = new ConcurrentHashMap<String, UnMutablePoint>(inputMap);
        unmutableMap = Collections.unmodifiableMap(inputMap);
    }


    public UnMutablePoint getLocation(String name) {
        if (name == null) throw new IllegalArgumentException();
        UnMutablePoint loc = locations.get(name);
        return loc.getPoint();

    }

    public void setLocation(String name, UnMutablePoint point) {
        if (name != null) {
            locations.replace(name, point.getPoint());
        }
    }

    public Map<String, UnMutablePoint> getLocations() {
        return this.unmutableMap;
    }
}
